// view/my/diancan/fenglxq/fenglxq.js
let app = getApp()
let yuming = app.globalData.yuming
const request = require('../../config/request');
Page({
  /**
   * 页面的初始数据
   */
  ...request,
  data: {
    buttonClicked: false,
    yuming: yuming,
    heights: '',
    title: "分类管理详情",
    iddazhe: false,
    id: '',
    xq: [],
    ssfllist: [{
      className: '顶级分类',
      id: 0
    }], //所属分类
    ssflindex: 0,
    ssflguo: '',
    fid: 0
  },
  bindssfl(e) {
    this.setData({
      ssflguo: this.data.ssfllist[e.detail.value].className,
      fid: this.data.ssfllist[e.detail.value].id
    })
  },
  // 详情接口
  xq() {
    var that = this
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'hallfood/goodsFindClass', {
      shopId: wx.getStorageSync('shopId'),
      id: that.data.id
    }, 'POST').then(res => {
      wx.hideLoading();
      var t = res.data.data.result.isShow
      var isguan = ''
      if (t == 1) {
        isguan = false
      } else {
        isguan = true
      }
      that.setData({
        xq: res.data.data.result,
        iddazhe: isguan,
        className: res.data.data.result.className,
        solt: res.data.data.result.solt,
        isShow: t,
        // ssflguo: res.data.data.result.fname,
      })
      if (res.data.data.result.fid == 0) {
        that.setData({
          ssflguo: '顶级分类'
        })
      } else {
        that.setData({
          ssflguo: res.data.data.result.fname
        })
      }
    })
  },
  // 保存
  bao() {
    var that = this
    that.setData({
      buttonClicked: true
    })
    this.myRequest(yuming + 'hallfood/goodsSaveClass', {
      shopId: wx.getStorageSync('shopId'),
      id: that.data.id,
      fid: that.data.fid,
      className: that.data.className,
      solt: that.data.solt,
      isShow: that.data.isShow
    }, 'POST').then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        setTimeout(function () {
          wx.navigateBack({
            delta: 1
          })
          that.setData({
            buttonClicked: false
          })
        }, 1000)
      } else {
        that.setData({
          buttonClicked: false
        })
      }

    })
  },
  // 是否显示
  bindazhe() {
    this.setData({
      iddazhe: !this.data.iddazhe
    })
    if (this.data.iddazhe) {
      this.setData({
        isShow: 0
      })
    } else {
      this.setData({
        isShow: 1
      })
    }
  },
  backs() {
    wx.navigateBack({
      delta: 1
    })
  },
  // 分类名称
  flmc(e) {
    this.setData({
      className: e.detail.value
    })
  },
  // 排序
  solt(e) {
    this.setData({
      solt: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  // 分类列表
  canzlist(e) {
    var that = this
    this.myRequest(yuming + 'hallfood/goodsSelectClass', {
      shopId: wx.getStorageSync('shopId'),
      fid: 0
    }, 'POST').then(res => {
      that.setData({
        ssfllist: that.data.ssfllist.concat(res.data.data.result)
      })
    })
  },
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      id: options.id,
      fid: options.fid,
      ssflguo: this.data.ssfllist[this.data.ssflindex].className
    })
    if (this.data.isShow == 0) {
      this.setData({
        iddazhe: true
      })
    } else {
      this.setData({
        iddazhe: false
      })
    }
  },
  //删除
  shan() {
    var that = this
    wx.showModal({
      title: '确定要删除该分类吗？',
      cancelText: '否',
      confirmText: '是',
      success(res) {
        if (res.confirm) {
          console.log("是")
          that.myRequest(yuming + 'hallfood/goodsDelClass', {
            shopId: wx.getStorageSync('shopId'),
            id: that.data.id
          }, 'POST').then(res => {
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
            if (res.data.code == 200) {
              setTimeout(function () {
                wx.navigateBack({
                  delta: 1
                })
              }, 1000)
            }
          })
        } else {
          console.log("否")
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.xq()
    this.canzlist()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})